﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Collection.cs" company="Marcelo Roca">
//   Copyright (c) 2011 Marcelo Roca. All rights reserved.
// </copyright>
// <author name="Marcelo Roca" email="marce@marceloroca.com"/>
// <license>
//   This program is free software: you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
// 
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program.  If not, see http://www.gnu.org/licenses/.
// </license>
// --------------------------------------------------------------------------------------------------------------------

namespace GameKits.Unity.GuiForms.Controls
{
    using System.Collections.Generic;

    public class Collection<T> where T : Control
    {
        /// <summary>
        /// La lista de controles
        /// </summary>
        private readonly HashSet<T> controlList = new HashSet<T>();

        /// <summary>
        /// Adicionamos un control a la colección
        /// </summary>
        /// <param name="control">
        /// The control.
        /// </param>
        public void Add(T control)
        {
            this.controlList.Add(control);
        }

        /// <summary>
        /// Adicionamos varios controles a la colección
        /// </summary>
        /// <param name="controls">
        /// The control.
        /// </param>
        public void Add(params T[] controls)
        {
            foreach (var item in controls)
            {
                this.controlList.Add(item);
            }
        }

        /// <summary>
        /// Eliminar los controles de la lista
        /// </summary>
        public void Clear()
        {
            this.controlList.Clear();
        }

        /// <summary>
        /// Indica si el control esta en la lista
        /// </summary>
        /// <param name="control">
        /// The control.
        /// </param>
        /// <returns>
        /// True si existe el control en la lista
        /// </returns>
        public bool Contains(T control)
        {
            return this.controlList.Contains(control);
        }

        /// <summary>
        /// Pintar los controles de la colección
        /// </summary>
        public void DrawInnercontrols()
        {
            foreach (var control in this.controlList)
            {
                control.DoOnGui();
            }
        }

        /// <summary>
        /// Quitar un control de la lista
        /// </summary>
        /// <param name="control">
        /// The control.
        /// </param>
        /// <returns>
        /// True si lo pudo elimianr
        /// </returns>
        public bool Remove(T control)
        {
            return this.controlList.Remove(control);
        }
    }
}
